<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unit tests for the Wordcount plugin</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="qunit/connector.js"></script>
<script type="text/javascript" src="qunit/runner.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/tiny_mce_loader.js"></script>
</head>
<body>
<script type="text/javascript">
var editor;

QUnit.config.reorder = false;
QUnit.config.autostart = false;

module("_getCount", { 
	autostart: false
});

test("Blank document has 0 words", function() {
	expect(1);

	editor.setContent('');
	var result = editor.plugins.wordcount._getCount(editor);
	equal(result, 0);
});

test("Simple word count", function() {
	expect(1);

	editor.setContent('<p>My sentence is this.</p>');
	var result = editor.plugins.wordcount._getCount(editor);
	equal(result, 4);
});

test("Does not count dashes", function() {
	expect(1);

	editor.setContent('<p>Something -- ok</p>');
	var result = editor.plugins.wordcount._getCount(editor);
	equal(result, 2);
});

test("Does not count asterisks, non-word characters", function() {
	expect(1);

	editor.setContent('<p>* something\n· something else</p>');
	var result = editor.plugins.wordcount._getCount(editor);
	equal(result, 3);
});

test("Does not count htmlentities", function() {
	expect(1);

	editor.setContent('<p>It&rsquo;s my life &ndash; don\'t you forget.</p>');
	var result = editor.plugins.wordcount._getCount(editor);
	equal(result, 6);
});

test("Counts hyphenated words as one word", function() {
	expect(1);

	editor.setContent('<p>Hello some-word here.</p>');
	var result = editor.plugins.wordcount._getCount(editor);
	equal(result, 3);
});

/*
The blocking functionality in the wordcount plugin prevents this code from
being tested correctly.

I'm of the opinion that the blocking code isn't really doing 
anything crucial, and should be ripped out, so this module can be tested.
---------
test("should set the word count in the target html element", function() {
	expect(1);
	editor.setContent('<p>Hey, it\'s me!</p>');
	equal(parseInt(document.getElementById('elm1-word-count').innerHTML), 3);
});
*/

tinyMCE.init({
	mode : "exact",
	elements : "elm1",
	theme : "advanced",
	add_unload_trigger : false,
	wordcount_target_id: 'current-count',
	plugins : 'wordcount',
	init_instance_callback : function(ed) {
		editor = ed;
		QUnit.start();
	}
});
</script>

<h1 id="qunit-header">Unit tests for the Wordcount plugin</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>

<div id="word-count">
	Current Count: <span id="current-count"></span>
</div>

<textarea id="elm1" name="elm1"></textarea>
<div>
	<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent({format : 'raw'}));">[getRawContents]</a>
	<a href="javascript:alert(tinymce.EditorManager.get('elm1').getContent());">[getContents]</a>
</div>
</body>
</html>
